package com.tsystems.train.bean;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.annotation.PostConstruct;
import javax.ejb.EJB;
import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.inject.Named;

import com.tsystems.train.entity.Ticket;
import com.tsystems.train.entity.TimeTableElement;
import com.tsystems.train.service.TicketServices;

@Named("myTicketsTableBean")
@RequestScoped
public class MyTicketsTableBean implements Serializable {

	private static final long serialVersionUID = 2165793273424547096L;

	@EJB
	private TicketServices ticketService;

	

	@Inject
	private UserBean user;

	private TTETableDataModel tteTableDataModel;

	public MyTicketsTableBean() {

		tteTableDataModel = new TTETableDataModel();

	}

	@PostConstruct
	public void init() {

		updateTable();

	}

	public void updateTable() {
		List<Ticket> result = ticketService.viewTickets(user.getLogin());
		ArrayList<TimeTableElement> elements= new ArrayList<TimeTableElement>(result.size());
		for(Ticket ticket : result){
			elements.add(ticket.getTimeTableElement());
		}
		tteTableDataModel.setWrappedData(elements);

	}

	public TTETableDataModel getTteTableDataModel() {
		return tteTableDataModel;
	}

}
